#include<stdio.h>
#include<stdlib.h>

#define eleType int

typedef struct Node
{
    eleType data;
    struct Node *next;  
}Node;

typedef struct  {
    Node *head;
    size_t size;

} Stack;


void CreateStack(Stack* stk){
    stk -> head= NULL;
    stk -> size= 0;

}

void StackDestory(Stack *stk){
    while (stk -> head)
    {
        Node *next = stk -> head -> next;
        free(stk -> head);
        stk -> head = next;
    }
    stk -> size = 0;
    
}


void StackPush(Stack *stk, eleType element){
    Node *newNode = (Node *)malloc(sizeof(Node));
    newNode -> data = element;
    newNode -> next = stk -> head;
    stk -> head = newNode;
    stk ->size++;
}

eleType StackPop(Stack *stk){
    if(stk -> size == 0){
        printf("Stack underflow\n");
        exit(1);
    }
    eleType result = stk -> head -> next;
    Node *next = stk->head ->next;
    free(stk -> head);
    stk -> head = next;
    stk -> size--;
    return result;
}

